package com.cat.twoPointerTechnique;

/**
*   @description https://leetcode.cn/problems/minimum-time-to-make-rope-colorful/
*   @author 曲大人的喵
*   @create 2025/8/8 19:55
*   @since JDK17
*/

public class Solution26 {
    public int minCost(String colors, int[] neededTime) {
        int n = colors.length() - 1, ans = 0, start, sum, max;
        for (int i = 0; i < n; ) {
            start = i;
            sum = max = neededTime[i];
            char t = colors.charAt(i++);
            while (i < n && t == colors.charAt(i)) {
                sum += neededTime[i];
                max = Math.max(max, neededTime[i++]);
            }
            if (i > start + 1) ans += sum - max;
        }
        return ans;
    }
}
